<?php

/**
 * @BelongProject: flamiManage
 * @Author: Zwc
 * @CreateTime: 2025-09-29 22:35:08
 * @Description: TODO
 */

namespace app\admin\controller;

use app\admin\service\CountryService;
use app\admin\service\LangDataService;
use cmf\controller\AdminBaseController;

class LangDataController extends AdminbaseController
{
    /**
     * 列表
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $params = $this->request->get();
        $countryData = $this->recommendLanguageData;
        $this->assign("countryData", $countryData);
        $this->assign('defaultLangId', $this->defaultLanguage['id']);
        if (empty($params['langId'])) {
            $this->assign('langId', $this->defaultLanguage['id']);
            $this->assign('langName', $this->defaultLanguage['name']);
        }else {
            $this->assign('langId', $params['langId']);
            $lang = CountryService::getOne($params['langId']);
            $this->assign('langName', $lang['name']);
        }
        return $this->fetch();
    }

    public function saveData()
    {
        $params = $this->request->post();
        (new LangDataService())->saveLangData($params);
        $this->success("操作成功!");
    }

    /**
     * 获取多语言
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getData() {
        $params = $this->request->get();
        return (new LangDataService())->getLangData($params['langId']);
    }

}